import { Controller, Post, Req, Res } from '@nestjs/common';
import { Request, Response } from 'express';
import { Messages } from 'protobuf/Messages';
import { LoginService } from './login.service';

@Controller('login')
export class LoginController {
    constructor(
        private readonly loginService: LoginService,
    ) {}

    @Post()
    async login(@Req() request:Request, @Res() response: Response)
    {
        let loginRequest = Messages.LoginRequest.decode(request.read());
        let loginResponse = this.loginService.login(loginRequest);
        let buffer = Messages.LoginRespone.encode(loginResponse).finish();
        response.send(buffer);
    }
}
